package com.kfm.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@WebFilter("/*")
public class CharsetFilter implements Filter {
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        // 获取一次 session, 如果是第一次访问就会创建 session， 从而使监听器执行
        req.getSession();

        req.setCharacterEncoding("utf-8");

        chain.doFilter(request, response);
    }
}
